package cn.coders.net.action;

import javax.annotation.Resource;

import org.apache.commons.lang.RandomStringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import cn.coders.net.service.DemoService;
import cn.coders.net.service.ManagerService;

import com.alibaba.fastjson.JSON;


/**
 * 项目名称：struts2</BR> <BR>
 * 包名文件名：.TestAction </BR> <BR>
 * 类名称： </BR> <BR>
 * 类描述： TODO</BR> <BR>
 * 创建人：王隐by632656576@qq.com</BR> <BR>
 * 创建时间：2015-4-24 下午04:09:01 </BR> <BR>
 * 修改人：王隐 </BR> <BR>
 * 修改时间：2015-4-24 下午04:09:01 </BR> <BR>
 * 修改备注： </BR> <BR>
 * 
 * @version </BR>
 * 
 */
@ParentPackage("json-default")
@Namespace(value = "/test")
public class TestAction extends BaseAction {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private String name;
    @Resource
    private DemoService service;

    @Resource
    private ManagerService managerService;


    @Action(value = "listAnswer", results = { @Result(name = SUCCESS, location = "/answer.jsp") })
    public String listAnswer() {
        System.out.println(service == null);
        name =
                service == null ? RandomStringUtils.randomNumeric(5) : service.productName(Integer
                    .parseInt(RandomStringUtils.randomNumeric(2)));
        return SUCCESS;
    }


    @Action(value = "listDb", results = { @Result(name = SUCCESS, location = "/answer.jsp") })
    public String listDb() {
        System.out.println(service == null);
        name =
                service == null ? RandomStringUtils.randomNumeric(5) : service.productName(Integer
                    .parseInt(RandomStringUtils.randomNumeric(2)));
        name = JSON.toJSONString(managerService.getAll());
        return SUCCESS;
    }


    public String getName() {
        return name;
    }


    @Resource
    public void setService(DemoService service) {
        this.service = service;
    }


    public void setName(String name) {
        this.name = name;
    }

}
